package Logic;

/**
 * Created by qq65827 on 2015/1/27.
 */
public class BubbleSort {

    public static void sort(int[] a) {
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < i; j++) {
                if (a[j] > a[i]) {
                    int temp = a[j];
                    a[j] = a[i];
                    a[i] = temp;
                }
            }
        }
    }

    public static void buble() {
        int[] a = {1, 45, 2, 1, 3, 4, 2, 12, 345, 23};
        for (int i = 0; i < a.length; i++) {
            for (int j = i; j < a.length; j++) {
                if (a[i] > a[j]) {
                    int temp = a[j];
                    a[j] = a[i];
                    a[i] = temp;
                }
            }
        }
        struct.utils.printInt(a);
    }

    public static void modifyBubble(int[] a) {
        for (int i = 0; i < a.length; i++) {
            for (int j = a.length - 2; j >= i; j--) {
                if (a[j] > a[j + 1]) {
                    int temp = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = temp;
                }
            }
        }
    }
}
